package teste;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class PanelOffice extends JPanel{

	
	 private Image image;
	    private Image image2;
	    private List<Image> trashes;
	    private Point[] points = {new Point(10,10),new Point(60,60),new Point(110,110),new Point(160,160)};
	    private int count= 0;
	    
	    public PanelOffice() {
	        this.initialize();
	    }

	    protected void initialize() {
	        this.image = this.getImage("resources/house/escritorio/escritorio.png");
	        
	        
	        this.image2 = this.getImage("resources/house/etc/jornais.png");
	        
	        this.trashes = new ArrayList<Image>();
	        for(int i=0;i<4;i++){
	        	this.trashes.add(image2);
	        }
	        
	      
	        this.setLayout(new BorderLayout());
	    }

	    public Image getImage(String path) {
	        //URL imageURL = getClass().getResource(path);
	        //if (imageURL == null)
	          //  return null;

	        return new ImageIcon(path).getImage();
	    }

	    public void paintComponent(Graphics g) {
	        super.paintComponent(g);
	        Dimension dDesktop = this.getSize();

	        double width = dDesktop.getWidth();
	        double height = dDesktop.getHeight();

	        Image background = new ImageIcon(this.image.getScaledInstance(
	                (int) width, (int) height, 1)).getImage();

	        Image t = new ImageIcon(this.image2.getScaledInstance(
	                75, 50, 1)).getImage();

	        g.drawImage(background, 0, 0, this);
	        
	        for(int i=0;i<count;i++){
	        	
	           g.drawImage(t,points[i].x,points[i].y,this);
	        }
	      
	    }
	    
	    /*public void paint(Graphics g) {
	    	// TODO Auto-generated method stub
	    	super.paint(g);
	    	
	    }*/
	    
	    public void addTrash() throws InterruptedException{
	    	 for(int i=0;i<trashes.size();i++){
	         	 
	    		 
	    		 
	    		 
	    			 
	    		 count++;
	    		 Thread.sleep(1000);
	    		 
	    		 repaint();
	         }
	         
	   
	    }
	    
	    public void removeTrash() throws InterruptedException {
	    	for(int i=0;i<trashes.size();i++){
	        	 
	   		 
	   		 count--;
	   		 Thread.sleep(1000);
	   		 repaint();
	        }
		}

	    public static void main(String[] args) throws InterruptedException {
	        JFrame frame = new JFrame();
	        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	        MyPanel p = new MyPanel();
	        frame.setContentPane(p);
	        frame.setSize(400, 300);
	        frame.setVisible(true);
	        p.addTrash();
	        p.removeTrash();
	        p.addTrash();
	        p.removeTrash();
	        p.addTrash();
	        p.removeTrash();
	       
	       
	        // frame.repaint(); 
	        }

}
